package com.zhouzhou.fastjava.util;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * User: liuzheqiang
 * Date: 2018/5/24
 * Time: 20:27
 */
public abstract class StringKit {

    private StringKit() {
    }

    public static boolean notEquals(String left, String right) {
        return !StringUtils.equals(left, right);
    }

    public static boolean notEqualsIgnoreCase(String left, String right) {
        return !StringUtils.equalsIgnoreCase(left, right);
    }

    public static String getMiddleString(String string, String start, String end) {
        int startIndex = string.indexOf(start) + start.length();
        return string.substring(startIndex, string.indexOf(end, startIndex));
    }

    public static String extract(String string, String regex, int group) {
        Matcher matcher = Pattern.compile(regex).matcher(string);
        if (matcher.find()) {
            return matcher.group(group);
        }
        return null;
    }

    public static String extract(String string, String regex) {
        return extract(string, regex, 1);
    }

    public static String md5(String string) {
        return DigestUtils.md5Hex(string);
    }

}
